<!-- f r o m 7 5  2 7 1  8 9 2 0 -->
<template>
  <a-row :gutter="24">
    <a-col :md="24">
      <a-card :style="cardStyle" :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <!-- 搜索区域 -->
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="24">
              <a-col :md="6" :sm="24">
                <a-form-item label="名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input placeholder="请输入客户名称/手机号查询" v-model="queryParam.customerId"></a-input>
                </a-form-item>
              </a-col>
              <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                <a-col :md="6" :sm="24">
                  <a-button type="primary" @click="searchQuery">查询</a-button>
                  <a-button style="margin-left: 8px" @click="searchReset">重置</a-button>
                </a-col>
              </span>
            </a-row>
          </a-form>
        </div>
        <!-- 操作按钮区域 -->
        <div class="table-operator" style="margin-top: 5px">
          <a-button v-if="btnEnableList.indexOf(1) > -1" @click="handleAdd" type="primary" icon="plus">新增</a-button>
          <a-button v-if="btnEnableList.indexOf(1) > -1" @click="batchDel" icon="delete">删除</a-button>
          <div style="width: 300px; float: right">
            <a-alert banner>
              <template slot="message">
                <a-tag color="green">绿色</a-tag>代表“OD”，<a-tag color="red">红色</a-tag>代表“OS”
              </template>
            </a-alert>
          </div>
        </div>
        <!-- table区域-begin -->
        <div>
          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            :dataSource="dataSource"
            :pagination="ipagination"
            :scroll="scroll"
            :loading="loading"
            :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
            @change="handleTableChange"
          >
            <a-table-column key="action" title="操作" data-index="action" :width="100" align="center">
              <template slot-scope="text, record">
                <a @click="handleEdit(record)">编辑</a>
                <a-divider v-if="btnEnableList.indexOf(1) > -1" type="vertical" />
                <a-popconfirm
                  v-if="btnEnableList.indexOf(1) > -1"
                  title="确定删除吗?"
                  @confirm="() => handleDelete(record.id)"
                >
                  <a>删除</a>
                </a-popconfirm>
              </template>
            </a-table-column>

            <a-table-column key="customerId" title="客户名称" data-index="customerName" :width="100" align="center" />
            <a-table-column
              key="customerMobile"
              title="客户手机"
              data-index="customerMobile"
              :width="120"
              align="center"
            />
            <a-table-column
              key="optometristName"
              title="验光师"
              data-index="optometristName"
              :width="100"
              align="center"
            />
            <a-table-column key="createTime" title="验光时间" data-index="createTime" :width="170" align="center">
              <template slot-scope="text, record, index">
                {{ moment(record.createTime).format('YYYY-MM-DD HH:mm:ss') }}
              </template>
            </a-table-column>
            <!-- <a-table-column key="title" title="双光/渐进" data-index="title" :width="100" align="center">
              <template slot-scope="text, record, index">
                <div>OD</div>
                <div>OS</div>
              </template>
            </a-table-column> -->
            <a-table-column key="sph" title="球镜" :width="90" align="center">
              <template slot-scope="text, record, index">
                <div style="margin-bottom: 7px">
                  <a-tag color="green">
                    {{ padZero(record.rSph, 2) }}
                  </a-tag>
                </div>
                <div>
                  <a-tag color="red">
                    {{ padZero(record.lSph, 2) }}
                  </a-tag>
                </div>
              </template>
            </a-table-column>
            <a-table-column key="cyl" title="柱镜" :width="90" align="center">
              <template slot-scope="text, record, index">
                <div style="margin-bottom: 7px">
                  <a-tag color="green">
                    {{ padZero(record.rCyl, 2) }}
                  </a-tag>
                </div>
                <div>
                  <a-tag color="red">
                    {{ padZero(record.lCyl, 2) }}
                  </a-tag>
                </div>
              </template>
            </a-table-column>
            <a-table-column key="ax" title="轴向" :width="90" align="center">
              <template slot-scope="text, record, index">
                <div style="margin-bottom: 7px">
                  <a-tag color="green">
                    {{ padZero(record.rAx, 0) }}
                  </a-tag>
                </div>
                <div>
                  <a-tag color="red">
                    {{ padZero(record.lAx, 0) }}
                  </a-tag>
                </div>
              </template>
            </a-table-column>
            <a-table-column key="add" title="Add" :width="90" align="center">
              <template slot-scope="text, record, index">
                <div style="margin-bottom: 7px">
                  <a-tag color="green">
                    {{ padZero(record.rAdd, 2) }}
                  </a-tag>
                </div>
                <div>
                  <a-tag color="red">
                    {{ padZero(record.lAdd, 2) }}
                  </a-tag>
                </div>
              </template>
            </a-table-column>
            <a-table-column key="bo" title="棱镜" :width="90" align="center">
              <template slot-scope="text, record, index">
                <div style="margin-bottom: 7px">
                  <a-tag color="green">
                    {{ padZero(record.rBo, 2) }}
                  </a-tag>
                </div>
                <div>
                  <a-tag color="red">
                    {{ padZero(record.lBo, 2) }}
                  </a-tag>
                </div>
              </template>
            </a-table-column>

            <a-table-column key="farPd" title="远用瞳距(mm)" :width="120" align="center">
              <template slot-scope="text, record, index">
                <div style="margin-bottom: 7px">
                  <a-tag color="green">{{ record.rFarPd }}</a-tag>
                </div>
                <div>
                  <a-tag color="red"> {{ record.lFarPd }}</a-tag>
                </div>
              </template>
            </a-table-column>
            <a-table-column key="nearPd" title="近用瞳距(mm)" :width="120" align="center">
              <template slot-scope="text, record, index">
                <div style="margin-bottom: 7px">
                  <a-tag color="green">{{ record.rNearPd }}</a-tag>
                </div>
                <div>
                  <a-tag color="red"> {{ record.lNearPd }}</a-tag>
                </div>
              </template>
            </a-table-column>
            <a-table-column key="ph" title="瞳高(mm)" :width="90" align="center">
              <template slot-scope="text, record, index">
                <div style="margin-bottom: 7px">
                  <a-tag color="green">{{ record.rPh }}</a-tag>
                </div>
                <div>
                  <a-tag color="red"> {{ record.lPh }}</a-tag>
                </div>
              </template>
            </a-table-column>

            <a-table-column key="farBcva" title="远用VA" :width="120" align="center">
              <template slot-scope="text, record, index">
                <div style="margin-bottom: 7px">
                  <a-tag color="green">
                    {{ padZero(record.rFarBcva, 1) }}
                  </a-tag>
                </div>
                <div>
                  <a-tag color="red">
                    {{ padZero(record.lFarBcva, 1) }}
                  </a-tag>
                </div>
              </template>
            </a-table-column>
            <a-table-column key="nearBcva" title="近用VA" :width="120" align="center">
              <template slot-scope="text, record, index">
                <div style="margin-bottom: 7px">
                  <a-tag color="green">
                    {{ padZero(record.rNearBcva, 1) }}
                  </a-tag>
                </div>
                <div>
                  <a-tag color="red">
                    {{ padZero(record.lNearBcva, 1) }}
                  </a-tag>
                </div>
              </template>
            </a-table-column>
          </a-table>
        </div>
        <!-- table区域-end -->
        <!-- 表单区域 -->
        <prescription-modal ref="modalForm" @ok="modalFormOk"></prescription-modal>
        <import-file-modal ref="modalImportForm" @ok="modalFormOk"></import-file-modal>
      </a-card>
    </a-col>
  </a-row>
</template>
<!-- BY cao_yu_li -->
<script>
import padEnd from 'lodash.padend'
import PrescriptionModal from './modules/PrescriptionModal'
import ImportFileModal from '@/components/tools/ImportFileModal'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JDate from '@/components/jeecg/JDate'
import Vue from 'vue'
import moment from 'moment'
export default {
  name: 'PrescriptList',
  mixins: [JeecgListMixin],
  components: {
    PrescriptionModal,
    ImportFileModal,
    JDate,
  },
  data() {
    return {
      labelCol: {
        span: 5,
      },
      wrapperCol: {
        span: 18,
        offset: 1,
      },
      // 查询条件
      queryParam: {
        customerId: null,
      },
      ipagination: {
        pageSizeOptions: ['10', '20', '30', '100', '200'],
      },
      url: {
        list: '/prescription/list',
        delete: '/prescription/delete',
        deleteBatch: '/prescription/deleteBatch',
      },
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}${this.url.importExcelUrl}`
    },
  },
  created() {},
  methods: {
    moment,
    padZero(value, precision = 2) {
      if (!value) {
        return ''
      }

      if (value.indexOf('.') != -1) {
        return value.split('.')[0] + '.' + padEnd(value.split('.')[1].substring(0, precision), precision, '0')
      } else if (precision > 0) {
        return value + '.' + padEnd('', precision, '0')
      } else {
        return value
      }
    },
    searchReset() {
      this.queryParam = {
        customerId: null,
      }
      this.loadData(1)
    },
    handleImportXls() {
      let importExcelUrl = this.url.importExcelUrl
      let templateUrl = '/doc/prescript_template.xls'
      let templateName = '处方Excel模板[下载]'
      this.$refs.modalImportForm.initModal(importExcelUrl, templateUrl, templateName)
      this.$refs.modalImportForm.title = '处方导入'
    },
    handleEdit: function (record) {
      this.$refs.modalForm.edit(record)
      this.$refs.modalForm.title = '编辑'
      this.$refs.modalForm.disableSubmit = false
      if (this.btnEnableList.indexOf(1) === -1) {
        this.$refs.modalForm.isReadOnly = true
      }
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
